package com.example.tyz1201.haha;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by tyz1201 on 2016/4/14.
 */
public class NetworkRequests {
    private URL url;
    private String data, line;

    public NetworkRequests(URL url, String data, String line) {
        this.url = url;
        this.data = data;
        this.line = line;
    }

    public String getDataFromSomewhere() {
        try {
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");

            InputStream is = conn.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);

            while ((line = br.readLine()) != null) {
                data = line + "\n";
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

        return data;
    }
}
